<template>
  <!-- 横排按钮布局 -->
  <view style="width: 100%">
    <template v-if="menuList.length > 0">
      <view class="drop-down-list">
        <view
          v-for="(item, index) in menuList"
          :key="index"
          class="drop-down-item"
          :style="
            currDefaultValue.includes(item.value)
              ? { background: itemActiveBackground, border: `1px solid ${activeColor}` }
              : { background: itemBackground, border: `1px solid ${itemBackground}` }
          "
          @click.stop.passive="subItemClick(item, index)"
        >
          <text class="item-text" :style="{ fontSize: itemFontSize, color: currDefaultValue.includes(item.value) ? activeColor : inactiveColor }">
            {{ item.label }}
          </text>
        </view>
      </view>
    </template>
    <template v-else>
      <view style="display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%" :style="{ height: menuHeight }">
        <image src="../../mxp-tool/static/images/global-state/not-data.svg" style="width: 120px; height: 120px" mode="scaleToFill"></image>
        <view>
          <text style="font-size: 14px" :style="{ color: inactiveColor }">暂无可选数据</text>
        </view>
      </view>
    </template>
  </view>
</template>

<script lang="ts" setup>
  import type { $AllColorStr, $SizeUnitStr } from '@/mxp-ui/mxp-tool/types/interface';
  import { type PropType, computed } from 'vue';

  import type { $TrimDropDownMultipleListLevel1Item } from './type';
  defineOptions({
    name: 'item-type7',
  });

  const props = defineProps({
    /** 每一项的筛选数据 */
    menuList: { type: Object as PropType<$TrimDropDownMultipleListLevel1Item[]>, required: true },
    /** 未选中颜色 */
    inactiveColor: { type: String as PropType<$AllColorStr>, required: true },
    /** 选中颜色颜色 */
    activeColor: { type: String as PropType<$AllColorStr>, required: true },
    /** 筛选列表的高度 */
    menuHeight: { type: String as PropType<$SizeUnitStr>, required: true },
    /** 筛选 列表的每一项 的文字大小 */
    itemFontSize: { type: String as PropType<$SizeUnitStr>, required: true },
    /** 筛选列表每一项的背景色（仅针对 type为 2,3,4,7 有效） */
    itemBackground: { type: String as PropType<$AllColorStr>, required: true },
    /** 筛选列表每一项选中时的背景色 */
    itemActiveBackground: { type: String as PropType<$AllColorStr>, required: true },
    /** 默认选中 */
    defaultValue: { type: [Array, Object] as PropType<Record<number | string, unknown[]> | unknown[] | undefined>, default: undefined },
  });

  const emits = defineEmits<{
    (e: 'click', item: $TrimDropDownMultipleListLevel1Item, menuIndex: number): void;
  }>();

  const currDefaultValue = computed<unknown[]>(() => (props.defaultValue || []) as unknown[]);

  /** 点击事件 */
  function subItemClick(item: $TrimDropDownMultipleListLevel1Item, menuIndex: number) {
    emits('click', item, menuIndex);
  }
</script>

<style scoped lang="scss">
  .drop-down-list {
    display: flex;
    flex-flow: row wrap;
    align-items: center;
    justify-content: flex-start;
    padding: 0 10px;

    .drop-down-item {
      display: inline-flex;
      flex-flow: row wrap;
      align-items: center;
      justify-content: space-between;
      padding: 6px 15px;
      margin: 6px;
      color: #333333;
      border: 1px solid #e5e5e5;
      border-radius: 4px;
      transition:
        background 0.3s,
        border 0.3s;

      .item-text {
        transition: color 0.3s;
      }
    }
  }
</style>
